package Scuttlebutt;

import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import Scuttlebutt.*;

public class ButtonBar extends JToolBar 
{
	private JButton connect = null;
	private JButton newProject = null;
	private JButton openProject = null;
	private JButton saveProject = null;
	private JButton closeProject = null;
	
	Scuttlebutt parent = null;
	ImageIcon i_up_connect = null;
	ImageIcon i_down_connect = null;
	ImageIcon i_disabled_connect = null;
	ImageIcon i_rollover_connect = null;
	
	ImageIcon i_up_disconnect = null;
	ImageIcon i_down_disconnect = null;
	ImageIcon i_disabled_disconnect = null;
	ImageIcon i_rollover_disconnect = null;
	
	public ButtonBar(Scuttlebutt parent)
	{
		this.parent = parent;
		setFloatable(false);
		setupButtonBar(parent);
		enableAllButtons(false);
	}
	
	public void setupButtonBar(Scuttlebutt parent){
		i_up_connect = parent.createImageIcon( "/images/up connect.jpg");
		i_down_connect = parent.createImageIcon("/images/down connect.jpg");
		i_disabled_connect = parent.createImageIcon("/images/disable connect.jpg");
		i_rollover_connect = parent.createImageIcon("/images/rollover connect.jpg");



		i_up_disconnect = parent.createImageIcon("/images/up disconnect.jpg");
		i_down_disconnect = parent.createImageIcon("/images/down disconnect.jpg");
		i_disabled_disconnect = parent.createImageIcon("/images/disable disconnect.jpg");
		i_rollover_disconnect = parent.createImageIcon("/images/rollover disconnect.jpg");

		connect = new JButton();
		connect.setBorder(javax.swing.BorderFactory.createMatteBorder(0,0,0,0, java.awt.Color.BLACK));
		setConnectButtonConnect();	
		connect.setToolTipText("Connect");
		connect.setEnabled(false);//
		connect.addActionListener(new EventConnect(parent));
		add(connect);
		
		addSeparator();
		
		newProject = new JButton();
		newProject.setBorder(javax.swing.BorderFactory.createMatteBorder(0,0,0,0, java.awt.Color.BLACK));
		newProject.setIcon(parent.createImageIcon("/images/up new project.jpg"));
		newProject.setPressedIcon(parent.createImageIcon("/images/down new project.jpg"));
		newProject.setDisabledIcon(parent.createImageIcon("/images/disable new project.jpg"));
		newProject.setRolloverIcon(parent.createImageIcon("/images/rollover new project.jpg"));
		newProject.setToolTipText("New Project");
		newProject.setEnabled(true);
		newProject.addActionListener(new EventNewProject(parent));
		add(newProject);		
		
		openProject = new JButton();
		openProject.setBorder(javax.swing.BorderFactory.createMatteBorder(0,0,0,0, java.awt.Color.BLACK));
		openProject.setIcon(parent.createImageIcon("/images/up open project.jpg"));
		openProject.setPressedIcon(parent.createImageIcon("/images/down open project.jpg"));
		openProject.setDisabledIcon(parent.createImageIcon("/images/disable open project.jpg"));
		openProject.setRolloverIcon(parent.createImageIcon("/images/rollover open project.jpg"));
		openProject.setToolTipText("Open Project");
		openProject.setEnabled(true);
		openProject.addActionListener(new EventOpenProject(parent));
		add(openProject);
		
		saveProject = new JButton();
		saveProject.setBorder(javax.swing.BorderFactory.createMatteBorder(0,0,0,0, java.awt.Color.BLACK));
		saveProject.setIcon(parent.createImageIcon("/images/up save project.jpg"));
		saveProject.setPressedIcon(parent.createImageIcon("/images/down save project.jpg"));
		saveProject.setDisabledIcon(parent.createImageIcon("/images/disable save project.jpg"));
		saveProject.setRolloverIcon(parent.createImageIcon("/images/rollover save project.jpg"));
		saveProject.setToolTipText("Save Project");
		saveProject.setEnabled(true);
		saveProject.addActionListener(new EventSaveProject(parent));
		add(saveProject);

		closeProject = new JButton();
		closeProject.setBorder(javax.swing.BorderFactory.createMatteBorder(0,0,0,0, java.awt.Color.BLACK));
		closeProject.setIcon(parent.createImageIcon("/images/up close project.jpg"));
		closeProject.setPressedIcon(parent.createImageIcon("/images/down close project.jpg"));
		closeProject.setDisabledIcon(parent.createImageIcon("/images/disable close project.jpg"));
		closeProject.setRolloverIcon(parent.createImageIcon("/images/rollover close project.jpg"));
		closeProject.setToolTipText("Close Project");
		closeProject.setEnabled(true);
		closeProject.addActionListener(new EventCloseProject(parent));
		add(closeProject);



	}

	public void setConnectButtonConnect(){
		connect.setIcon(i_up_connect);
		connect.setPressedIcon(i_down_connect);
		connect.setDisabledIcon(i_disabled_connect);
		connect.setRolloverIcon(i_rollover_connect);
		//setDisabledSelectedIcon(Icon disabledSelectedIcon)
		//setSelectedIcon(Icon selectedIcon)
	}
	
	public void setConnectButtonDisconnect(){
		connect.setIcon(i_up_disconnect);
		connect.setPressedIcon(i_down_disconnect);
		connect.setDisabledIcon(i_disabled_disconnect);
		connect.setRolloverIcon(i_rollover_disconnect);
	}
	
	public JButton getConnectButton(){
		return connect;
	}
	
	public void enableNewProjectButton(boolean state){
		newProject.setEnabled(state);
	}

	public void enableOpenProjectButton(boolean state){
		openProject.setEnabled(state);
	}
	
	public void enableSaveProjectButton(boolean state){
		saveProject.setEnabled(state);
	}

	public void enableCloseProjectButton(boolean state){
		closeProject.setEnabled(state);
	}	
	
	public void enableAllButtons(boolean state){
		connect.setEnabled(state);
		newProject.setEnabled(state);
		openProject.setEnabled(state);
		saveProject.setEnabled(state);
		closeProject.setEnabled(state);
	}
}

